package com.akkkka.strategy.yml;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

import java.io.File;
import java.util.logging.Logger;

import static com.akkkka.Constants.LOG_LEVEL;
import static com.akkkka.Constants.ruoyi_STRING;
import static com.akkkka.RenameConfig.MY_PROJECT_NAME;

/**
 * @author: akkkka114514
 * @create: 2025-08-03 14:08
 * @description:
 */
public class JobYmlRenameStrategy extends YamlRenameStrategy{
    private static final Logger logger;

    private static final YAMLMapper yamlMapper;
    static{
        logger = Logger.getLogger(YamlRenameStrategy.class.getName());
        logger.setLevel(LOG_LEVEL);

        YAMLFactory yamlFactory = new YAMLFactory();
        yamlMapper = new YAMLMapper(yamlFactory);
        yamlMapper.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES);
    }
    @Override
    public boolean supports(File file) {
        return file.getName().equals(MY_PROJECT_NAME+"-job.yml");
    }

    @Override
    public void rename(File file) {
        logger.info("重命名xxx-job.yml:"+file.getAbsolutePath());
        JsonNode rootNode = parse(file);
        renameValue(rootNode, "snail-job.group", ruoyi_STRING, MY_PROJECT_NAME);
        renameValue(rootNode, "snail-job.server.server-name", ruoyi_STRING, MY_PROJECT_NAME);

        writeFile(file, rootNode);
        logger.info("重命名xxx-job.yml完成:"+file.getAbsolutePath());
    }
}
